import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Register from '../views/Register.vue'
import Recognize from '../views/Recognize.vue'
import UserManagement from '../views/UserManagement.vue'
import NotFound from '../views/NotFound.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: { title: '人脸识别系统 - 首页' }
  },
  {
    path: '/register',
    name: 'Register',
    component: Register,
    meta: { title: '人脸识别系统 - 人脸注册' }
  },
  {
    path: '/recognize',
    name: 'Recognize',
    component: Recognize,
    meta: { title: '人脸识别系统 - 人脸识别' }
  },
  {
    path: '/users',
    name: 'UserManagement',
    component: UserManagement,
    meta: { title: '人脸识别系统 - 用户管理' }
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: NotFound,
    meta: { title: '页面不存在' }
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

// 路由前置守卫，设置页面标题
router.beforeEach((to, from, next) => {
  document.title = to.meta.title || '人脸识别系统'
  next()
})

export default router